package com.ambitor.grass.sql.statement;

import java.sql.Connection;

import com.ambitor.grass.sql.data.Parameter;


public class BatchParameterStatementImpl extends ParameterStatementImpl
		implements BatchOperation {

	private Parameter[] params;
	
	public BatchParameterStatementImpl(Connection conn, String sql, Parameter[] params) throws Exception {
		super(conn, sql);
		this.params = params;
	}
	
	public int[] executeBatch() throws Exception {
		if (this.params.length == 0) return new int[0];
		for (int i = 0; i < this.params.length; ++i) {
			setParameters(this.params[i]);
			this.getStatement().addBatch();
		}
		int[] result = this.getStatement().executeBatch();
		this.close();     //
		return result;
	}

}
